package handler

import (
	"github.com/anaskhan96/go-password-encoder"
	"hash"
)

type Options struct {
	SaltLen      int
	Iterations   int
	KeyLen       int
	HashFunction func() hash.Hash
	OriginalPwd  string
}

func PasswordEncode(opt Options) (string, string) {
	options := &password.Options{SaltLen: opt.SaltLen, Iterations: opt.Iterations, KeyLen: opt.KeyLen, HashFunction: opt.HashFunction}
	salt, encodedPwd := password.Encode(opt.OriginalPwd, options)
	return salt, encodedPwd
}

func VerifyPassword(salt string, encodedPwd string, opt Options) bool {
	options := &password.Options{SaltLen: opt.SaltLen, Iterations: opt.Iterations, KeyLen: opt.KeyLen, HashFunction: opt.HashFunction}
	check := password.Verify(opt.OriginalPwd, salt, encodedPwd, options)
	return check
}
